package com.itheima.service.impl;

import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * value属性就是对象的id
 * 如果不指定value属性，那么id就是类名首字母改小写
 */
@Component(value = "userServiceImpl")
//@Scope(value = "prototype")
public class UserServiceImpl implements UserService {

    @Value("张三")
    private String username;

    @PostConstruct
    public void init(){
        System.out.println("init()方法被调用了....");
    }


    @PreDestroy
    public void destroy(){
        System.out.println("destroy()方法被调用了...");
    }

    @Override
    public String getName() {
//        return "张三";
        return username;
    }
}
